/*
 * Copyright (C) 2017 Honeywell, Inc. All Rights Reserved.
 */

package org.thanos.demo.nats;

import io.nats.client.Message;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;

public class AsyncNatsConsumerPool {

    private ExecutorService threadPool;

    public AsyncNatsConsumerPool() {
        threadPool = Executors.newCachedThreadPool();
    }

    public AsyncNatsConsumerPool(Integer nThreads) {
        threadPool = Executors.newFixedThreadPool(nThreads);
    }

    public void submit(final Message message, final Consumer<Message> consumer) {
        this.threadPool.submit(() -> consumer.accept(message));
    }
}
